﻿using LY.Common;
using LY.Entity;
using LY.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LY.DataAccess.Repository;
using LY.Entity.PageSearch;
using LY.Entity.SearchEntity;

namespace LY.Business.ServiceImpl
{
    class SiteconfigService : ISiteconfigService
    {
        private static readonly object lockHelper = new object();
         SiteconfigRepository _site;
         public SiteconfigService()
        {
            _site = new SiteconfigRepository();
        }
        //保存信息
        public long SaveSiteconfig(S_Siteconfig sc)
        {

            long flag = 0;
            flag = sc.Id==0 ? _site.Insert(sc) : _site.Update(sc);

            if (flag > 0)
            {
                SaveConifg(sc, Utility.GetXmlMapPath("Configpath"));
            } 
            return flag;  
        }

        public   S_Siteconfig LoadConfig()
        {
            return (S_Siteconfig)SerializationHelper.Load(typeof(S_Siteconfig), Utility.GetXmlMapPath("Configpath"));
        }
        /// <summary>
        ///  读取站点配置文件
        /// </summary>
        public S_Siteconfig LoadConfig(string configFilePath)
        {
            return (S_Siteconfig)SerializationHelper.Load(typeof(S_Siteconfig), configFilePath);
        }

        /// <summary>
        /// 写入站点配置文件
        /// </summary>
        private S_Siteconfig SaveConifg(S_Siteconfig model, string configFilePath)
        {
            lock (lockHelper)
            {
                SerializationHelper.Save(model, configFilePath);
            }
            return model;
        }
        //根据ID获取网站配置信息
        public S_Siteconfig getSiteconfig()
        {
            return _site.getSiteconfig();
        }
    }
}
